package greetings

import (
	"errors"
	"fmt"
)

// Hello
// 函数必须首字母大写才能被其他模块所使用
func Hello(name string) (string, error) {

	if name == "" {
		return "", errors.New("name must not be null")
	}

	result := fmt.Sprintf("Hi, %s ,Welcome!", name)

	return result, nil
}

func Hellos(names []string) (map[string]string, error) {
	// 创建一个map
	messages := make(map[string]string)

	for index, name := range names {

		message, err := Hello(name)
		if err != nil {
			return messages, errors.New(fmt.Sprintf("第%d个名称为[%s]的抛出了异常 %v", index, name, err))
		}
		messages[name] = message
	}

	return messages, nil
}
